<?php
namespace app\common\model;
use app\common\cache\CacheData;

class City extends Base
{
	public function cacheData(){
		$data = $this -> select();
		if($data){
			foreach($data as &$value):
				$value = $value->toArray();
			endforeach;
		}
		return $data;
	}

	/**
     * 系统配置缓存
     * @return [type] [description]
     */
    public static function cityData(){
        $CACHE = CacheData::getInstance('City');
        //$CACHE -> updateCache();
        $cacheData = $CACHE -> readCache();
        return $cacheData;
    }

    /**
     * 通过省查市/通过市查县
     * @param  [type] $parent [description]
     * @return [type]           [description]
     */
    public static function findByParent($parent){
        $cacheData = self::cityData();
        $data = [];
        foreach($cacheData as $value):
            if($value['root']==$parent){
                $data[] = $value;
            }
        endforeach;
        return $data;
    }

    /**
     * 通过ID查名称
     * @param  [type] $parent [description]
     * @return [type]           [description]
     */
    public static function findName($data=''){
        $cacheData = self::cityData();
        foreach($cacheData as $value):
            if($value['id']==$data){
                return $value['name'];
            }
        endforeach;
    }

}
